{template 'common/header'}

<ul class="nav nav-tabs">
	<li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('cate', array('op' => 'post'))}">添加分类</a></li>
	<li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('cate', array('op' => 'display'))}">管理分类</a></li>
</ul>
<script>
	require(['bootstrap'],function($){
		$('.btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
	});
</script>
{if $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
		<div class="panel panel-default">
			<div class="panel-heading">
				商品分类
			</div>
			<div class="panel-body">
				{if !empty($parentid)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
					<div class="col-sm-9 col-xs-12 control-label" style="text-align:left;">{$parent['name']}</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="displayorder" class="form-control" value="{$category['displayorder']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>分类名称</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="catename" class="form-control" value="{$category['name']}" />
					</div>
				</div>

				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类图片</label>
					<div class="col-sm-9 col-xs-12">
						{php echo tpl_form_field_image('thumb', $category['thumb'])}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>
					<div class="col-sm-9 col-xs-12">
						<textarea name="description" class="form-control" cols="70">{$category['description']}</textarea>
					</div>
				</div>
			

			
				 <div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
					<div class="col-sm-9 col-xs-12">
						<label class='radio-inline'>
							<input type='radio' name='enabled' value=1' {if $category['enabled']==1}checked{/if} /> 是
						</label>
						<label class='radio-inline'>
							<input type='radio' name='enabled' value=0' {if $category['enabled']==0}checked{/if} /> 否
						</label>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>

{elseif $operation == 'display'}
<div class="main">
	<div class="category">
		<form action="" method="post" onsubmit="return formcheck(this)">
			<div class="panel panel-default">
				<div class="panel-body table-responsive">
					<table class="table table-hover">
						<thead>
							<tr>
								<th style="width:10px;"></th>
								<th style="width:80px;">显示顺序</th>
								<th style="width:300px;">分类名称</th>
								<th style="width:150px;">状态</th>
								<th style="width:150px;">操作</th>
							</tr>
						</thead>
						<tbody>
						{loop $category $row}
						<tr>
							<td>{if count($children[$row['id']]) > 0}<a href="javascript:;"><i class="fa fa-chevron-down"></i></a>{/if}</td>
							<td><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
							<td>
								<img src="{php echo tomedia($row['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' />
								<div class="type-parent">{$row['name']}
									
								</div>
							</td>
							
							<td>
								{if $row['enabled']==1}
								<span class='label label-success'>显示</span>
								{else}
								<span class='label label-danger'>隐藏</span>
								{/if}
							</td>
							<td>
								<a href="{php echo $this->createWebUrl('cate', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;
								<a href="{php echo $this->createWebUrl('cate', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-times"></i></a>
							</td>
						</tr>
						{loop $children[$row['id']] $row}
						<tr>
							<td></td>
							<td>
								<input type="text" class="form-control col-lg-2" name="displayorder[{$row['id']}]" value="{$row['displayorder']}">
							</td>
							<td>
								<div style="padding-left:50px;height:30px;line-height:30px;background:url('./resource/images/bg_repno.gif') no-repeat -245px -545px;">{$row['name']}
									<img src="{php echo tomedia($row['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' />&nbsp;&nbsp;
								</div>
							</td>
							<td>
								<strong style="color:red;">{$row['id']}</strong>
							</td>
							<td>
								{if $row['enabled']==1}
								<span class='label label-success'>显示</span>
								{else}
								<span class='label label-danger'>隐藏</span>
								{/if}
							</td>
							<td>
								<a href="{php echo $this->createWebUrl('cate', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;
								<a href="{php echo $this->createWebUrl('cate', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-times"></i></a>
							</td>
						</tr>
						{/loop}
						{/loop}
						<tr>
							<td></td>
							<td colspan="4">
								<a href="{php echo $this->createWebUrl('cate', array('op' => 'post'))}"><i class="fa fa-plus-sign-alt"></i> 添加新分类</a>
							</td>
						</tr>
						<tr>
							<td></td>
							<td colspan="4">
								<input name="submit" type="submit" class="btn btn-primary" value="提交">
								<input type="hidden" name="token" value="{$_W['token']}" />
							</td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>
		</form>
	</div>
</div>
{/if}
{template 'common/footer'}
